package novel.front.novellist.test.thred;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class MyThreadLocal {
//    private   static final ThreadLocal<HashMap> threadLocal = new ThreadLocal<HashMap>(){
//         @Override
//         protected HashMap initialValue() {
//             System.out.println(Thread.currentThread().getName()+"initialValue");
//             return new HashMap();
//         }
//    };



    public static class T1 implements Runnable {

        private final static Map map = new Hashtable();

        int id;

        String name;

        public T1(int id,String name) {

            this.id = id;

            this.name = name;

        }

        public void run() {

            // Map map = threadLocal.get();
            map.put(name, name+"sss");
            for (int i = 0; i < 20; i++) {

                map.put(i, i + id * 100);

                try {

                    Thread.sleep(100);

                } catch (Exception ex) {

                }

            }

            System.out.println(Thread.currentThread().getName() + "# map.size()=" + map.size() + " # " + map);

        }

    }

    public static void main(String[] args) {

//        Thread[] runs = new Thread[15];

        T1 t = new T1(1,"sss111");
        new Thread(t).start();
        T1 t2 = new T1(2,"sss333");
        new Thread(t2).start();


//        for (int i = 0; i < runs.length; i++) {
//
//            runs[i] = new Thread(t);
//
//        }
//
//        for (int i = 0; i < runs.length; i++) {
//
//            runs[i].start();
//
//        }

    }
}
